package com.kx.insta.traitement;

import com.temboo.Library.Facebook.Reading.GetUnreadMessages;
import com.temboo.Library.Facebook.Reading.Likes;
import com.temboo.Library.Twitter.Search.Tweets.TweetsResultSet;
import com.temboo.Library.Twitter.Timelines.HomeTimeline.HomeTimelineResultSet;
import com.temboo.Library.Twitter.Timelines.Mentions;
import com.temboo.Library.Utilities.JSON.GetValuesFromJSON;
import com.temboo.Library.Utilities.JSON.GetValuesFromJSON.GetValuesFromJSONInputSet;
import com.temboo.Library.Utilities.JSON.GetValuesFromJSON.GetValuesFromJSONResultSet;
import com.temboo.core.TembooException;
import com.temboo.core.TembooSession;
import java.util.ArrayList;
import java.util.Arrays;
import org.json.JSONArray;
import org.json.JSONException;

/**
 *
 * @author KX
 */
public abstract class afficherResultat {
    
        public static String showResult(TweetsResultSet tweetsResults,TembooSession session) throws TembooException{
           String s1 = recupererChampDateTweets(tweetsResults, session, "created_at");
           ArrayList<String> a1 = Split(s1);
           String s2 = recupererChampDateTweets(tweetsResults, session, "name");
                      ArrayList<String> a2 = Split(s2);
           String s3 = recupererChampDateTweets(tweetsResults, session, "text");
                      ArrayList<String> a3 = Split(s3);
           ArrayList<String> a4 = new ArrayList<>();
           int i =1;
           String f="";
            //System.out.println(a1.size() +"  " + a2.size() +"  " +a3.size());
            i = Math.min( a1.size(),a2.size());
            i = Math.min(i, a3.size());
           String s = "";
            System.out.println("\n");
           for (int j=0 ; j < i; j++){
               f = a1.get(j)+" : "+a2.get(j)+" : "+a3.get(j);
               a4.add(f);
              s = s + f +"\n\n"; 
           }
               
           //String s4 = (s1.concat("\n"+s2)).concat("\n"+s3);
            //System.out.println(s);
            
           return s;
        }
    
        public static String  showResult(HomeTimelineResultSet homeTimelineResults,TembooSession session) throws JSONException, TembooException{
            
            String s1 = recupererChampDateTimeline(homeTimelineResults, session, "created_at");
           ArrayList<String> a1 = Split(s1);
           String s2 = recupererChampDateTimeline(homeTimelineResults, session, "name");
                      ArrayList<String> a2 = Split(s2);
           String s3 = recupererChampDateTimeline(homeTimelineResults, session, "text");
                      ArrayList<String> a3 = Split(s3);
           ArrayList<String> a4 = new ArrayList<>();
           int i =1;
           String f="";
            //System.out.println(a1.size() +"  " + a2.size() +"  " +a3.size());
            i = Math.min( a1.size(),a2.size());
            i = Math.min(i, a3.size());
           String s = "";
            System.out.println("\n");
           for (int j=0 ; j < i; j++){
               f = a1.get(j)+" : "+a2.get(j)+" : "+a3.get(j);
               a4.add(f);
              s = s + f +"\n\n"; 
           }
           return s;
        }

        public static String showResult(Mentions.MentionsResultSet mentionsResults,TembooSession session) throws TembooException{
        
              String s1 = recupererChampDateMentions(mentionsResults, session, "created_at");
           ArrayList<String> a1 = Split(s1);
           String s2 = recupererChampDateMentions(mentionsResults, session, "name");
                      ArrayList<String> a2 = Split(s2);
           String s3 = recupererChampDateMentions(mentionsResults, session, "text");
                      ArrayList<String> a3 = Split(s3);
           ArrayList<String> a4 = new ArrayList<>();
           int i =1;
           String f="";
            System.out.println(a1.size() +"  " + a2.size() +"  " +a3.size());
            i = Math.min( a1.size(),a2.size());
            i = Math.min(i, a3.size());
           String s = "";
            System.out.println("\n");
           for (int j=0 ; j < i; j++){
               f = a1.get(j)+" : "+a2.get(j)+" : "+a3.get(j);
               a4.add(f);
              s = s + f +"\n\n"; 
           }
            
           return s;
           
        }

        public static void showResult(Likes.LikesResultSet likesResults){}
        
        public static void showResult(GetUnreadMessages.GetUnreadMessagesResultSet getUnreadMessagesResults) throws JSONException{
            JSONArray obj = new JSONArray(getUnreadMessagesResults.get_Response());
                    if(obj!=null)
                    {

                        for (int i=0;i<obj.length();i++){
                            System.out.println("Message "+ i +":\n"+obj.getString(i)+"\n\n");
                            }
                    }
                    else {System.out.println("data est null");
                    } //To change body of generated methods, choose Tools | Templates.
                    
        }
        
        public static String recupererChampNomtimeline(HomeTimelineResultSet homeTimelineResults ,TembooSession session,String string) throws TembooException{
                         GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(homeTimelineResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
                    //System.out.println(getValuesFromJSONResults.get_Response());   
                    return getValuesFromJSONResults.get_Response();
        }
        
        public static String recupererChampMessageTimeline(HomeTimelineResultSet homeTimelineResults ,TembooSession session,String string) throws TembooException{
            
                GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(homeTimelineResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
                    //System.out.println(getValuesFromJSONResults.get_Response());   
                    return getValuesFromJSONResults.get_Response();

        }
        
        public static String recupererChampDateTimeline(HomeTimelineResultSet homeTimelineResults ,TembooSession session,String string) throws TembooException{
        // Instantiate the Choreo, using a previously instantiated TembooSession object, eg:
                // TembooSession session = new TembooSession("smalten", "myFirstApp", "d7c2e7cf553542639bfd278829fb9ae4");

                GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(homeTimelineResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
                //System.out.println(getValuesFromJSONResults.get_Response());
                return getValuesFromJSONResults.get_Response();
        }
        
        public static String recupererChampDateTweets(TweetsResultSet tweetsResults ,TembooSession session,String string) throws TembooException{
                
              
                GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(tweetsResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
                //System.out.println(getValuesFromJSONResults.get_Response());
                return getValuesFromJSONResults.get_Response();
        }
            
        public static String recupererChampTextTweets(TweetsResultSet tweetsResults ,TembooSession session,String string) throws TembooException{


                GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(tweetsResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
                //System.out.println(getValuesFromJSONResults.get_Response());
                return getValuesFromJSONResults.get_Response();
        }    
       
        public static String recupererChampNomTweets(TweetsResultSet tweetsResults ,TembooSession session,String string) throws TembooException{
   
                GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(tweetsResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
               // System.out.println(getValuesFromJSONResults.get_Response());
                return getValuesFromJSONResults.get_Response();

        }
       
        public static String recupererChampNomMentions(Mentions.MentionsResultSet mentionsResults,TembooSession session,String string) throws TembooException{
                 
            GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(mentionsResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
                    //System.out.println(getValuesFromJSONResults.get_Response()); 
                   return getValuesFromJSONResults.get_Response();
        }
        
        public static String recupererChampMessageMentions(Mentions.MentionsResultSet mentionsResults,TembooSession session,String string) throws TembooException{
            
            
                GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(mentionsResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
                    //System.out.println(getValuesFromJSONResults.get_Response()); 
                  return  getValuesFromJSONResults.get_Response();

        }
        
        public static String recupererChampDateMentions(Mentions.MentionsResultSet mentionsResults ,TembooSession session,String string) throws TembooException{
        
                GetValuesFromJSON getValuesFromJSONChoreo = new GetValuesFromJSON(session);

                // Get an InputSet object for the choreo
                GetValuesFromJSONInputSet getValuesFromJSONInputs = getValuesFromJSONChoreo.newInputSet();

                // Set inputs
                getValuesFromJSONInputs.set_JSON(mentionsResults.get_Response());
                getValuesFromJSONInputs.set_Property(string);

                // Execute Choreo
                GetValuesFromJSONResultSet getValuesFromJSONResults = getValuesFromJSONChoreo.execute(getValuesFromJSONInputs);
               // System.out.println(getValuesFromJSONResults.get_Response());
               // ArrayList <String> stringArray =null;
               return getValuesFromJSONResults.get_Response();
        }
        
        public static ArrayList <String> Split(String string){
            //System.out.println(string);
             ArrayList<String> stringArray = new ArrayList();
             stringArray.addAll(Arrays.asList(string.split(",")));
        return stringArray;
        }
             
}